package cn.aiyuan.controller;

import cn.aiyuan.domain.User;
import cn.aiyuan.service.UserService;
import com.baomidou.mybatisplus.extension.api.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author wangyuan
 * @date 2021/6/2
 */
@RestController
@RequestMapping("/api/aiyuan/user")
@Api(tags = "用户测试")
public class UserController {

    @Resource
    private UserService userService;

    @ApiOperation("保存用户")
    @PostMapping
    public R<Boolean> insert(@RequestBody User user) {
        return R.ok(userService.save(user));
    }

    @ApiOperation("批量保存用户")
    @PostMapping("/batch")
    public R<Boolean> insert(@RequestBody List<User> users) {
        return R.ok(userService.saveBatch(users));
    }

    @GetMapping("/all")
    public R<List<User>> selectAll() {
        return R.ok(userService.list());
    }

    @GetMapping("/{id}")
    public R<User> getById(@PathVariable Long id) {
        return R.ok(userService.getById(id));
    }
}
